# use normal make for this Makefile
#
# Makefile for building user programs to run on top of Nachos
#
# Several things to be aware of:
#
#    Nachos assumes that the location of the program startup routine (the
# 	location the kernel jumps to when the program initially starts up)
#       is at location 0.  This means: start.o must be the first .o passed 
# 	to ld, in order for the routine "Start" to be loaded at location 0
#

# If you are running on SunOS 5.x machines, uncomment the next line
GCCDIR = /auto/home-scf-22/csci402/testgnu/decstation-ultrix/bin/
LDFLAGS = -T newscript -N
ASFLAGS = -mips1
CPPFLAGS = $(INCDIR)

# if you aren't cross-compiling:
# GCCDIR =
# LDFLAGS = -N -T 0
# ASFLAGS =
# CPPFLAGS = -P $(INCDIR)


CC = $(GCCDIR)gcc
AS = $(GCCDIR)as
LD = $(GCCDIR)ld
CPP = $(GCCDIR)cpp

INCDIR =-I../userprog -I../threads -I../test
CFLAGS = -G 0 -c $(INCDIR)


all: halt threadTest matmult sort testfiles lockstest homedepotentry  exectest forktest calledByExecTest badexectest multitest exittest

start.o: start.s ../userprog/syscall.h
	$(CPP) $(CPPFLAGS) start.s > strt.s
	$(AS) $(ASFLAGS) -o start.o strt.s
	rm strt.s

usercommon.o: usercommon.c
	$(CC) $(CFLAGS) -c usercommon.c

threadTest.o: threadTest.c
	$(CC) $(CFLAGS) -c threadTest.c
threadTest: threadTest.o start.o usercommon.o
	$(LD) $(LDFLAGS) start.o usercommon.o threadTest.o  -o threadTest.coff
	../bin/coff2noff threadTest.coff threadTest

multitest.o: multitest.c
	$(CC) $(CFLAGS) -c multitest.c
multitest: multitest.o start.o usercommon.o
	$(LD) $(LDFLAGS) start.o usercommon.o multitest.o  -o multitest.coff
	../bin/coff2noff multitest.coff multitest


halt.o: halt.c
	$(CC) $(CFLAGS) -c halt.c
halt: halt.o start.o
	$(LD) $(LDFLAGS) start.o halt.o -o halt.coff
	../bin/coff2noff halt.coff halt

sort.o: sort.c
	$(CC) $(CFLAGS) -c sort.c
sort: sort.o start.o
	$(LD) $(LDFLAGS) start.o sort.o -o sort.coff
	../bin/coff2noff sort.coff sort

matmult.o: matmult.c
	$(CC) $(CFLAGS) -c matmult.c
matmult: matmult.o start.o
	$(LD) $(LDFLAGS) start.o matmult.o -o matmult.coff
	../bin/coff2noff matmult.coff matmult

testfiles.o: testfiles.c
	$(CC) $(CFLAGS) -c testfiles.c
testfiles: testfiles.o start.o
	$(LD) $(LDFLAGS) start.o testfiles.o -o testfiles.coff
	../bin/coff2noff testfiles.coff testfiles
	
lockstest.o: lockstest.c
	$(CC) $(CFLAGS) -c lockstest.c
lockstest: lockstest.o start.o
	$(LD) $(LDFLAGS) start.o usercommon.o lockstest.o -o lockstest.coff
	../bin/coff2noff lockstest.coff lockstest
	
homedepotentry.o: homedepotentry.c
	$(CC) $(CFLAGS) -c homedepotentry.c
homedepotentry: homedepotentry.o start.o
	$(LD) $(LDFLAGS) start.o usercommon.o homedepotentry.o -o homedepotentry.coff
	../bin/coff2noff homedepotentry.coff homedepotentry
	
exectest.o: exectest.c
	$(CC) $(CFLAGS) -c exectest.c
exectest: exectest.o start.o usercommon.o
	$(LD) $(LDFLAGS) start.o usercommon.o exectest.o -o exectest.coff
	../bin/coff2noff exectest.coff exectest
	
badexectest.o: badexectest.c
	$(CC) $(CFLAGS) -c badexectest.c
badexectest: badexectest.o start.o usercommon.o
	$(LD) $(LDFLAGS) start.o usercommon.o badexectest.o -o badexectest.coff
	../bin/coff2noff badexectest.coff badexectest
	
	
forktest.o: forktest.c
	$(CC) $(CFLAGS) -c forktest.c
forktest: forktest.o start.o usercommon.o
	$(LD) $(LDFLAGS) start.o usercommon.o forktest.o -o forktest.coff
	../bin/coff2noff forktest.coff forktest

calledByExecTest.o: calledByExecTest.c
	$(CC) $(CFLAGS) -c calledByExecTest.c
calledByExecTest: calledByExecTest.o start.o usercommon.o
	$(LD) $(LDFLAGS) start.o usercommon.o calledByExecTest.o -o calledByExecTest.coff
	../bin/coff2noff calledByExecTest.coff calledByExecTest
	
exittest.o: exittest.c
	$(CC) $(CFLAGS) -c exittest.c
exittest: exittest.o start.o usercommon.o
	$(LD) $(LDFLAGS) start.o usercommon.o exittest.o -o exittest.coff
	../bin/coff2noff exittest.coff exittest


clean:
	rm -f *.o *.coff
